package com.wutong.eams.utils;

import java.util.Map;

public class RouterUtil {

    public enum MatchType {
        EXACT,   // 精确匹配
        PREFIX   // 前缀匹配
    }

    public static boolean isWhiteListed(String requestUri, Map<String, MatchType> whiteList) {
        // 先移除查询参数
        String path = requestUri.split("\\?")[0];

        for (Map.Entry<String, MatchType> entry : whiteList.entrySet()) {
            String whitePath = entry.getKey();
            MatchType type = entry.getValue();

            if (type == MatchType.EXACT && path.equals(whitePath)) {
                return true;
            } else if (type == MatchType.PREFIX && path.startsWith(whitePath)) {
                // 对于前缀匹配，确保是完整的路径段
                if (path.length() == whitePath.length() ||
                        path.charAt(whitePath.length()) == '/') {
                    return true;
                }
            }
        }
        return false;
    }

}
